#include<iostream>
#include<cstring>
#include<ctime>
using namespace std;



void MaxSum(int* a, int nsize);


int main()
{
		int arr[10] = {2,-4,3,5,-2,6,-3,-1,5,-6,};
		MaxSum(arr, 10);
		cin.get();
		return 0;
}

void MaxSum(int* a, int nsize)
{
		int sum = 0; 
		int tempsum = 0;
		int bIndex=0,eIndex=0;
		bool bAllNeg = (a[0]>0) ? false : true;
		for( int i = 0; i < nsize; ++i)
		{
			if( tempsum < 0 )
			{
				tempsum = a[i];
				if( bAllNeg )
					sum = tempsum;
				bIndex = i;
			}
			else
			{
				tempsum += a[i];
				eIndex = i;
				if( tempsum > sum)
					sum = tempsum;
			}
		}
		cout<<"Max sum is "<<sum<<endl;
		cout<<"It begins at "<<bIndex<<" & ends at "<<eIndex<<endl;
}
